package com.gxa.hystrix.service;

import com.gxa.hystrix.interfaces.ServiceFeignByCheck;
import com.gxa.hystrix.pojo.GuaHaoJiLu;
import com.gxa.hystrix.pojo.HuanZheJiuZhenKa;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author thinknovo
 * @version 1.0
 * @description CheckService.java
 * @date 2021/3/11 9:25
 */
@Service
public class CheckService {
    @Resource
    private ServiceFeignByCheck serviceFeignByCheck;

    // 通过feign调用服务模块，如果触发熔断机制，则会调用此注解checkError定义的方法
    // 熔断器会检查所有的client是否存在，如果都不存在，则会触发HystrixCommand
    @HystrixCommand(fallbackMethod = "checkError")
    public Map check(String username) {
        return serviceFeignByCheck.selectClient(username);
    }
    public Map checkError(String username) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }

    @HystrixCommand(fallbackMethod = "chaXunYiShengError")
    public Map chaXunYiSheng(String id ,String yiShengLeiXing) {
        return serviceFeignByCheck.chaXunYiSheng(id , yiShengLeiXing);
    }
    public Map chaXunYiShengError(String id ,String yiShengLeiXing) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }

    @HystrixCommand(fallbackMethod = "huanZheJiuZhenKaChaXunError")
    public Map huanZheJiuZhenKaChaXunAll() {
        return serviceFeignByCheck.huanZheJiuZhenKaChaXunAll();
    }
    public Map huanZheJiuZhenKaChaXunError() {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }
    @HystrixCommand(fallbackMethod = "huanZheJiuZhenKaGengXinByIdError")
    public Map huanZheJiuZhenKaGengXinById(HuanZheJiuZhenKa huanZheJiuZhenKa) {
        return serviceFeignByCheck.huanZheJiuZhenKaGengXinById(huanZheJiuZhenKa);
    }
    public Map huanZheJiuZhenKaGengXinByIdError(HuanZheJiuZhenKa huanZheJiuZhenKa) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }

    @HystrixCommand(fallbackMethod = "huanZheJiuZhenKaChaXunByKaHaoError")
    public Map huanZheJiuZhenKaChaXunByKaHao(String huanZheKaHao,String shenFenZheng,String xingMing,
                           String shouJiHao,String kaiShiShiJian,String jieShuShiJian) {
        return serviceFeignByCheck.huanZheJiuZhenKaChaXunByKaHao(huanZheKaHao,shenFenZheng,xingMing,shouJiHao,kaiShiShiJian,jieShuShiJian);
    }
    public Map huanZheJiuZhenKaChaXunByKaHaoError(String huanZheKaHao,String shenFenZheng,String xingMing,
                                                  String shouJiHao,String kaiShiShiJian,String jieShuShiJian) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }

    @HystrixCommand(fallbackMethod = "chaXunKeShiError")
    public Map chaXunKeShi() {
        return serviceFeignByCheck.chaXunKeShi();
    }
    public Map chaXunKeShiError() {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }

    @HystrixCommand(fallbackMethod = "guaHaoJiLuChaXunAllError")
    public Map guaHaoJiLuChaXunAll() {
        return serviceFeignByCheck.guaHaoJiLuChaXunAll();
    }
    public Map guaHaoJiLuChaXunAllError() {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }

    @HystrixCommand(fallbackMethod = "guaHaoJiLuGengXinByIdError")
    public Map guaHaoJiLuGengXinById(GuaHaoJiLu guaHaoJiLu) {
        return serviceFeignByCheck.guaHaoJiLuGengXinById(guaHaoJiLu);
    }
    public Map guaHaoJiLuGengXinByIdError(GuaHaoJiLu guaHaoJiLu) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }

    @HystrixCommand(fallbackMethod = "guaHaoJiLuTuiHaoByIdError")
    public Map guaHaoJiLuTuiHaoById(String id) {
        return serviceFeignByCheck.guaHaoJiLuTuiHaoById(id);
    }
    public Map guaHaoJiLuTuiHaoByIdError(String id) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }

    @HystrixCommand(fallbackMethod = "guaHaoJiLuXinZengError")
    public Map guaHaoJiLuXinZeng(GuaHaoJiLu guaHaoJiLu) {
        return serviceFeignByCheck.guaHaoJiLuXinZeng(guaHaoJiLu);
    }
    public Map guaHaoJiLuXinZengError(GuaHaoJiLu guaHaoJiLu) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }




}
